<template>
  <div class="app-container">

    <el-collapse v-model="activeNames" @change="handleChange">

      <el-card class="box-card d1">
        <p style="font-size: 14px"><a @click="back"><i class="el-icon-back" style="width: 20px"></i>返回</a></p>
        <!--      <h4><i class="el-icon-paperclip"></i> 基本信息</h4>-->
        <el-collapse-item title="基本信息" name="1">
          <el-row>
            <el-col :span="24">
              <el-form label-position="labelPosition"  ref="formPatient" :model="formPatient" :rules="rulesPatient" label-width="80px"  >
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="姓名" prop="patientName">
                      <el-input v-model="formPatient.patientName" placeholder="请输入姓名" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="身份证号" prop="idCard">
                      <el-input v-model="formPatient.idCard" placeholder="请输入身份证号" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="性别" prop="gender">
                      <el-select v-model="formPatient.gender" placeholder="请选择性别" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_doctor_sex"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="年龄" prop="age">
                      <el-input v-model="formPatient.age" placeholder="请输入患者年龄" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="出生日期" prop="patientDate">
                      <el-date-picker clearable v-model="formPatient.patientDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择出生日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="样本编号" prop="outpatient">
                      <el-input v-model="formPatient.outpatient" placeholder="请输入样本编号" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="采血单位" prop="unit">
                      <el-input v-model="formPatient.unit" placeholder="请输入采血单位" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="门诊号" prop="sliceNo">
                      <el-input v-model="formPatient.sliceNo" placeholder="请输入门诊号/住院号" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="是否初筛" prop="screen">
                      <el-select v-model="formPatient.screen" placeholder="请选择是否初筛" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_screen"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <!--              <el-col :span="8">
                                  <el-form-item label="采血日期" prop="ctime">
                                    <el-date-picker clearable v-model="formPatient.ctime" type="date" value-format="yyyy-MM-dd"  placeholder="请选择采血日期">
                                    </el-date-picker>
                                  </el-form-item>
                                </el-col>-->
                  <el-col :span="8">
                    <el-form-item label="身高" prop="height">
                      <el-tooltip class="item" effect="light" content="单位：cm" placement="right">
                        <el-input v-model="formPatient.height" @input="getBmi" placeholder="请输入身高" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="体重" prop="weight">
                      <el-tooltip class="item" effect="light" content="单位：kg" placement="right">
                        <el-input v-model="formPatient.weight" @input="getBmi" placeholder="请输入体重" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="婚姻状况" prop="marital">
                      <el-select v-model="formPatient.marital" placeholder="请选择婚姻状况" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_marital_type"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="文化程度" prop="degree">
                      <el-select v-model="formPatient.degree" placeholder="请选择文化程度" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_degree"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="经济来源" prop="income">
                      <el-select v-model="formPatient.income" placeholder="请选择经济来源" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_income"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="居住情况" prop="living">
                      <el-select v-model="formPatient.living" placeholder="请选则居住情况" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_living"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="主要照顾者" prop="caregiver">
                      <el-select v-model="formPatient.caregiver" placeholder="请选则主要照顾者" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_caregiver"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="常住地址" prop="address">
                      <el-input v-model="formPatient.address" placeholder="请输入常住地址" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="电话/手机" prop="tel">
                      <el-input v-model="formPatient.tel" placeholder="请输入患者电话" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">
                    <el-form-item label="是否转院" prop="director">
                      <el-select v-model="formPatient.director" placeholder="请选则是否转院" clearable>
                        <el-option
                          v-for="(dict,index) in dict.type.his_director"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <!--              <el-col :span="8">
                                  <el-form-item label="采血人" prop="collector">
                                    <el-input v-model="formPatient.collector" placeholder="请输入采血人" />
                                  </el-form-item>
                                </el-col>-->

                  <!--              <el-col :span="8">
                                  <el-form-item label="信息录入者" prop="createBy">
                                    <el-input v-model="formPatient.createBy" placeholder="请输入信息录入者" />
                                  </el-form-item>
                                </el-col>-->

                  <!--              <el-col :span="8">
                                  <el-form-item label="审核者" prop="reviewer">
                                    <el-input v-model="formPatient.reviewer" placeholder="请输入审核者" />
                                  </el-form-item>
                                </el-col>-->

                  <!--              <el-col :span="8">
                                  <el-form-item label="录入时间" prop="patientDate">
                                    <el-date-picker clearable v-model="formPatient.createTime" type="date" value-format="yyyy-MM-dd"  placeholder="请选择录入时间">
                                    </el-date-picker>
                                  </el-form-item>
                                </el-col>-->

                  <el-col :span="8">
                    <el-form-item label="备注" prop="remark">
                      <el-input v-model="formPatient.remark" type="textarea" placeholder="请输入备注" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="筛查结果" prop="status">
                      <el-select v-model="formPatient.status" placeholder="请选择筛查结果" clearable>
                        <el-option
                          v-for="(dict,index) in selectOptions.status"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                          :disabled="dict.disabled"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-col>
          </el-row>
          <el-row>
            <div class="op-container" style="float: right">
              <el-button @click="handleCancel">返回</el-button>
              <el-button type="primary" :loading="btnLoading" @click="submitForm(true)">更新</el-button>
            </div>
          </el-row>
        </el-collapse-item>
      </el-card>

      <el-card class="box-card d12">
        <el-collapse-item title="评测指标" name="2">
          <el-row>
            <el-col :span="24">
              <el-divider ><span v-if="formAttribute.formula==1">计算模型一/27个指标</span><span v-if="formAttribute.formula==2">计算模型二/26个指标</span><span v-if="formAttribute.formula==3">计算模型三/5个指标</span><span v-if="formAttribute.formula==4" >计算模型四/8个指标</span><span v-if="formAttribute.formula==5" >计算模型五/7个指标</span></el-divider>
              <el-form label-position="labelPosition"  ref="formAttribute" :model="formAttribute" :rules="rulesAttribute" label-width="80px"  >
                <!--选择模型-->
                <el-row class="js-module">
                  <el-col :span="4">
                    <el-form-item label="请选择计算模型：" prop="formula" class="item_green">
                      <el-select v-model="formAttribute.formula" placeholder="请选择计算模型" @change="getBmi" :disabled="formPatient.status=='2'" style="width: 160px;">
                        <el-option
                          v-for="(dict,index) in dict.type.his_screening_calculate"
                          :key="index"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4" v-if="formPatient.status!='2'">
                    <el-form-item>
                      <el-button type="primary"  @click="submitCalculation" :disabled="formPatient.status=='2'">计算结果</el-button>
                    </el-form-item>
                  </el-col>
                </el-row>

                <!--肝功-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>肝功：</div>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="谷草转氨酶" prop="ast">
                      <el-tooltip class="item" effect="light" content="单位：u/L" placement="right">
                        <el-input v-model="formAttribute.ast" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="碱性磷酸酶" prop="acp">
                      <el-tooltip class="item" effect="light" content="单位：nM" placement="right">
                        <el-input v-model="formAttribute.acp" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="总蛋白质" prop="tp">
                      <el-tooltip class="item" effect="light" content="单位：g/L" placement="right">
                        <el-input v-model="formAttribute.tp" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                  <el-col :span="3" style="margin-left: 50px" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="丙氨酸氨基转移酶" prop="alt">
                      <el-tooltip class="item" effect="light" content="单位：U/L" placement="right">
                        <el-input v-model="formAttribute.alt" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--血脂-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>血脂：</div>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="甘油三酯" prop="tag">
                      <el-tooltip class="item" effect="light" content="单位：nmol/ml" placement="right">
                        <el-input v-model="formAttribute.tag" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="低密度脂蛋白" prop="ldl">
                      <el-tooltip class="item" effect="light" content="单位：nmol/ml" placement="right">
                        <el-input v-model="formAttribute.ldl" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--血常规-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>血常规：</div>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="红细胞" prop="rbc">
                      <el-tooltip class="item" effect="light"  placement="right">
                        <div slot="content">单位：x10<sup>12</sup>/L</div>
                        <el-input v-model="formAttribute.rbc" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="4" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="血红蛋白" prop="hgb">
                      <el-tooltip class="item" effect="light" content="单位：g/L" placement="right">
                        <el-input v-model="formAttribute.hgb" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="平均红细胞体积" prop="mcv">
                      <el-tooltip class="item" effect="light" content="单位：f" placement="right">
                        <el-input v-model="formAttribute.mcv" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="白细胞" prop="wbc">
                      <el-tooltip class="item" effect="light" placement="right">
                        <div slot="content">单位：x10<sup>9</sup>/L</div>
                        <el-input v-model="formAttribute.wbc" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="血小板计数" prop="plt">
                      <el-tooltip class="item" effect="light" placement="right">
                        <div slot="content">单位：x10<sup>9</sup>/L</div>
                        <el-input v-model="formAttribute.plt" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--肾功-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>肾功：</div>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="肌酐" prop="cre">
                      <el-tooltip class="item" effect="light" content="单位：μm" placement="right">
                        <el-input v-model="formAttribute.cre" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="胱仰素C" prop="cc">
                      <el-tooltip class="item" effect="light" content="单位：mg/L" placement="right">
                        <el-input v-model="formAttribute.cc" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--电解质-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>电解质：</div>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="磷" prop="p">
                      <el-tooltip class="item" effect="light" content="单位：mg" placement="right">
                        <el-input v-model="formAttribute.p" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="钾" prop="k">
                      <el-tooltip class="item" effect="light" content="单位：mg" placement="right">
                        <el-input v-model="formAttribute.k" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="钠" prop="na">
                      <el-tooltip class="item" effect="light" content="单位：mg" placement="right">
                        <el-input v-model="formAttribute.na" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--甲功-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>甲功：</div>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="甲状腺素（T4）" prop="trh">
                      <el-tooltip class="item" effect="light" content="单位：nM" placement="right">
                        <el-input v-model="formAttribute.trh" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="游离 T4" prop="ft4">
                      <el-tooltip class="item" effect="light" content="单位：pM" placement="right">
                        <el-input v-model="formAttribute.ft4" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--维生素-->
                <el-row>
                  <el-col :span="1" class="col_title" style="margin-bottom: 29px" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>维生素：</div>
                  </el-col>
                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="维生素D" prop="vd">
                      <el-tooltip class="item" effect="light" content="单位：ng/mL" placement="right">
                        <el-input v-model="formAttribute.vd" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==1 && formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="叶酸" prop="fa">
                      <el-tooltip class="item" effect="light" content="单位：nM" placement="right">
                        <el-input v-model="formAttribute.fa" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==1 && formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="维生素B12" prop="b12">
                      <el-tooltip class="item" effect="light" content="单位：pg/L" placement="right">
                        <el-input v-model="formAttribute.b12" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--其它-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <div>其它：</div>
                  </el-col>
                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="白细胞介素 -6" prop="il">
                      <el-tooltip class="item" effect="light" content="单位：ng/L" placement="right">
                        <el-input v-model="formAttribute.il" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==1 || formAttribute.formula==0">
                    <el-form-item label="空腹血糖" prop="fpg" class="item_yellow">
                      <el-tooltip class="item" effect="light" content="单位：mol/L" placement="right">
                        <el-input v-model="formAttribute.fpg" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula!=3 && formAttribute.formula!=4 && formAttribute.formula!=5">
                    <el-form-item label="白蛋白" prop="alb">
                      <el-tooltip class="item" effect="light" content="单位：g/L" placement="right">
                        <el-input v-model="formAttribute.alb" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==2 || formAttribute.formula==0">
                    <el-form-item label="同型半胱氨酸" prop="hcy" class="item_yellow">
                      <el-tooltip class="item" effect="light" content="单位：mol/L" placement="right">
                        <el-input v-model="formAttribute.hcy" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==2  || formAttribute.formula==0">
                    <el-form-item label="糖化血红蛋白" prop="hba1c" class="item_yellow">
                      <el-tooltip class="item" effect="light" content="单位：nmol/mL" placement="right">
                        <el-input v-model="formAttribute.hba1c" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==2 || formAttribute.formula==0">
                    <el-form-item label="25羟维生素D" prop="hvd" class="item_yellow">
                      <el-tooltip class="item" effect="light" content="单位：ng/mL" placement="right">
                        <el-input v-model="formAttribute.hvd" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                </el-row>
                <!--卧位收缩压-->
                <el-row v-if="formAttribute.formula==3 || formAttribute.formula==4 || formAttribute.formula==5">
                  <el-col :span="1" class="col_title">
                    <div></div>
                  </el-col>
                  <el-col :span="3" >
                    <el-form-item label="卧位收缩压" prop="rsp">
                      <el-tooltip class="item" effect="light" content="单位：mmHg" placement="right">
                        <el-input v-model="formAttribute.rsp" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3">
                    <el-form-item label="卧位舒张压" prop="kdp">
                      <el-tooltip class="item" effect="light" content="单位：mmHg" placement="right">
                        <el-input v-model="formAttribute.kdp" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--丙二醛-->
                <el-row>
                  <el-col :span="1" class="col_title">
                    <div></div>
                  </el-col>
                  <el-col :span="3">
                    <el-form-item label="丙二醛（MDA）" prop="mda" v-if="formAttribute.formula==3 || formAttribute.formula==1 || formAttribute.formula==2 || formAttribute.formula==0 || formAttribute.formula==4 || formAttribute.formula==5">
                      <el-tooltip class="item" effect="light" content="单位：umol/L" placement="right">
                        <el-input v-model="formAttribute.mda" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                  <el-col :span="3" v-if="formAttribute.formula==3 || formAttribute.formula==4 || formAttribute.formula==5">
                    <el-form-item label="年龄" prop="age">
                      <el-tooltip class="item" effect="light" content="单位：岁" placement="right">
                        <el-input v-model="formPatient.age" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                  <el-col :span="3" v-if="formAttribute.formula==3 || formAttribute.formula==4 || formAttribute.formula==5">
                    <el-form-item label="BMI" prop="bmi">
                      <el-tooltip class="item" effect="light" content="单位：kg/m²" placement="right">
                        <el-input v-model="formAttribute.bmi" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!--临时新增公式五-->
                <el-row>
                  <el-col :span="1" class="col_title" v-if="formAttribute.formula!=3">
                    <div></div>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==4 || formAttribute.formula==5">
                    <el-form-item label="小腿围" prop="xtw">
                      <el-tooltip class="item" effect="light" content="单位：cm" placement="right">
                        <el-input v-model="formAttribute.xtw" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==4 || formAttribute.formula==5">
                    <el-form-item label="握力" prop="wl" >
                      <el-tooltip class="item" effect="light" content="单位：kg" placement="right">
                        <el-input v-model="formAttribute.wl" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3" v-if="formAttribute.formula==4">
                    <el-form-item label="6米步速" prop="sbs">
                      <el-tooltip class="item" effect="light" content="单位：m/s" placement="right">
                        <el-input v-model="formAttribute.sbs" placeholder="" />
                      </el-tooltip>
                    </el-form-item>
                  </el-col>

                </el-row>
              </el-form>

            </el-col>
          </el-row>
        </el-collapse-item>
      </el-card>
      <el-card class="box-card d22">
        <el-row>
          <el-col :span="24">
            <div style="font-size: 14px; color: #949393">计算模型一（衰弱+肌少症）：27个指标，计算模型二（衰弱+肌少症）：26个指标（用同型半胱氨酸替代了维生素B12和叶酸，用糖化血红蛋白替代了空腹血糖，维生素D指标名更为25羟维生素D）</div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div style="font-size: 14px; color: #949393">计算模型三（衰弱）：5个指标（MDA、年龄、BMI、卧位收缩压、卧位舒张压）</div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div style="font-size: 14px; color: #949393">计算模型四（衰弱+肌少症）：8个指标（MDA、年龄、BMI、卧位收缩压、卧位舒张压、握力、小腿围、6米步速）</div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div style="font-size: 14px; color: #949393">计算模型五（衰弱+肌少症）：7个指标（MDA、年龄、BMI、卧位收缩压、卧位舒张压、握力、小腿围）</div>
          </el-col>
        </el-row>
        <el-divider content-position="left"></el-divider>
        <el-row>
          <el-col :span="24">
            <el-form label-position="labelPosition"  ref="formRisk" :model="formRisk" :rules="rulesRisk" label-width="80px">
              <el-row>
                <el-col :span="6">
                  <el-form-item label="风险计算模型" prop="riskModel">
                    <el-select v-model="formRisk.riskModel" placeholder="请选则风险计算模型" clearable>
                      <el-option
                        v-for="(dict,index) in dict.type.his_risk_calculation_model"
                        :key="index"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="样本类型" prop="sampleType">
                    <el-select v-model="formPatient.sampleType" placeholder="请选择样本类型" clearable>
                      <el-option
                        v-for="(dict,index) in dict.type.sample_type"
                        :key="index"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="送检科室" prop="department">
                    <el-input v-model="formRisk.department" placeholder="请输入送检科室" />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="送检医生" prop="department">
                    <el-input v-model="formRisk.docts" placeholder="请输入送检医生" />
                  </el-form-item>
                </el-col>
                <!--              <el-col :span="6">
                                <el-form-item label="采血人" prop="collector">
                                  <el-input v-model="formRisk.collector" placeholder="请输入采血人" />
                                </el-form-item>
                              </el-col>-->
                <el-col :span="6" class="date_pick">
                  <el-form-item label="采血日期" prop="ctime">
                    <el-date-picker clearable v-model="formRisk.ctime" type="datetime" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm:s"  placeholder="请选择采血日期">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="检验人" prop="inspector">
                    <el-input v-model="formRisk.inspector" placeholder="请输入检验人" />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="报告人" prop="report">
                    <el-input v-model="formRisk.report" placeholder="请输入报告人" />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="审核人" prop="reviewer">
                    <el-input v-model="formRisk.reviewer" placeholder="请输入审核人" />
                  </el-form-item>
                </el-col>
                <!--              <el-col :span="6" class="create_time">
                                <el-form-item label="录入时间" prop="create_time">
                                  <el-input v-model="formRisk.createTime" type="datetime" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm:s" placeholder="" readonly/>
                                </el-form-item>
                              </el-col>-->
                <el-col :span="6" class="date_pick">
                  <el-form-item label="送检时间" prop="receiveTime">
                    <el-date-picker clearable v-model="formRisk.receiveTime" type="datetime" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:s"  placeholder="请选择送检时间">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6" class="date_pick">
                  <el-form-item label="审核时间" prop="reviewTime">
                    <el-date-picker clearable v-model="formRisk.reviewTime" type="datetime" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:s"  placeholder="请选则审核时间">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6" class="date_pick">
                  <el-form-item label="报告时间" prop="reportTime">
                    <el-date-picker clearable v-model="formRisk.reportTime" type="datetime" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:s"  placeholder="请选则报告时间">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="临床" prop="lc">
                    <el-input v-model="formPatient.lc" placeholder="请输入临床" />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-col>
        </el-row>
        <el-row>
          <div class="op-container" style="float: right">
            <el-button @click="handleCancel">返回</el-button>
            <el-button type="primary" :loading="btnLoading" @click="submitForm(true)">更新</el-button>
          </div>
        </el-row>
      </el-card>

      <el-card class="box-card d3" v-if="visbleJsz">
        <!--      <h4 style="margin-bottom: 10px"><i class="el-icon-finished"></i> 老年衰弱/肌少症风险评估及建议</h4>-->
        <el-collapse-item title="评测结果" name="3">
          <el-row style="margin-bottom: 10px">
            <div class="op-container" style="float: right">
              <el-select v-model="reportType" style="width: 90px;margin-right: 10px">
                <el-option
                  v-for="(dict,index) in reportList"
                  :key="index"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
              <el-button :plain="true" type="primary" size="small" @click="loadPdf">报告预览</el-button>
            </div>
          </el-row>
          <el-table :data="screeningLn">
            <el-table-column property="screeningItem" label="筛查项目"/>
            <el-table-column property="screeningResult" label="筛查结果"/>
            <el-table-column property="referenceRange" label="参考范围"/>
            <el-table-column property="riskWarning" label="风险提示"/>
            <el-table-column property="advise" label="风险建议"/>
            <el-table-column align="center" label="操作" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button :plain="true" type="primary" size="mini" @click="handlePatientResult(scope.row,1)">设置</el-button>
                <el-button :plain="true" type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>

          <el-divider content-position="left">结论及建议</el-divider>
          <el-row style="margin-top: 20px" class="text_area">
            <el-col :span="24">
              <el-form label-position="labelPosition" ref="formAdvise" :model="formAdvise" :rules="rulesAdvise" label-width="80px"  >
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="" prop="lnAdvise">
                      <el-input type="textarea" v-model="formAdvise.lnAdvise" placeholder="" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-col>
          </el-row>
        </el-collapse-item>
      </el-card>

      <el-card class="box-card d4" v-if="visbleKspg">
        <h4><i class="el-icon-finished"></i> 快速综合评估结果</h4>
        <el-button :plain="true" type="primary" size="mini" @click="handlePatientResult({subscreening: queryKsParams.subscreening},2)">添加</el-button>
        <el-table :data="screeningKs">
          <el-table-column property="screeningItem" label="筛查项目"/>
          <el-table-column property="screeningResult" label="筛查结果"/>
          <el-table-column property="referenceRange" label="参考范围" width="360"/>
          <el-table-column property="riskWarning" label="风险提示"/>
          <el-table-column align="center" label="操作" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button :plain="true" type="primary" size="mini" @click="handlePatientResult(scope.row,2)">设置</el-button>
              <!--              <el-button :plain="true" type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>-->
            </template>
          </el-table-column>
        </el-table>

        <el-divider content-position="left">结论及建议</el-divider>
        <el-row style="margin-top: 20px" class="text_area">
          <el-col :span="24">
            <el-form label-position="labelPosition" ref="formAdvise" :model="formAdvise" :rules="rulesAdvise" label-width="80px"  >
              <el-row>
                <el-col :span="12">
                  <el-form-item label="" prop="ksAdvise">
                    <el-input type="textarea" v-model="formAdvise.ksAdvise" placeholder="" />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-col>
        </el-row>
      </el-card>

    </el-collapse>

    <el-dialog :visible.sync="resultVisiable" width="560px" title="风险计算结果">
      <el-form ref="formResult" :model="formResult" :rules="rulesResult" status-icon label-position="left" label-width="100px" style="width: 400px; margin-left:20px;">
        <el-form-item label="筛查项目" prop="screeningItem">

          <el-select v-model="formResult.screeningItem" placeholder="请选择筛查项目" clearable>
            <div v-if="this.dicts_state==2">
              <el-option
                v-for="(dict,index) in dict.type.his_screening_item"
                :key="index"
                :label="dict.label"
                :value="dict.value"
              />
            </div>
            <div v-if="this.dicts_state==1">
              <el-option
                v-for="dict in dict.type.his_saas_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </div>
          </el-select>
        </el-form-item>
        <el-form-item label="筛查结果" prop="screeningResult">
          <el-input v-model="formResult.screeningResult"/>
        </el-form-item>
        <el-form-item label="参考范围" prop="referenceRange">
          <el-input v-model="formResult.referenceRange"/>
        </el-form-item>
        <el-form-item label="风险提示" prop="riskWarning">
          <el-select v-model="formResult.riskWarning" placeholder="请选择风险类型" clearable>
            <el-option
              v-for="(dict,index) in dict.type.his_risk_type"
              :key="index"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="风险建议" prop="advise">
          <el-input v-model="formResult.advise"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resultVisiable = false">取消</el-button>
        <el-button type="primary" @click="handleResultEdit">确定</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport + '&patientId=' + upload.patientId"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            <el-input v-model="upload.patientId" type="hidden" ></el-input>
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="doc.title" :visible.sync="doc.open" >
      <template>
        <iframe :src="pathUrl" width="100%"></iframe>
      </template>
    </el-dialog>


    <div class="op-container">
      <el-button @click="handleCancel">返回</el-button>
      <el-button type="primary" :loading="btnLoading" @click="submitForm(true)">更新</el-button>
    </div>

  </div>
</template>

<style>
.fixed-width .el-button--mini {
  width: 60px !important;
}
.d1 .el-input {
  width: 79%;
}
.d1 .el-textarea__inner{
  width: 79% ;
}
.d1 .el-form-item__label {
  width: 102px !important;
}
.d1 .el-form-item__content{
  margin-left: 102px !important;
}

.d12 .el-input {
  width: 100%;
}
.d12 .el-textarea__inner{
  width: 100% ;
}
.d12 .el-form-item__label {
  width: 126px !important;
}
.d12 .el-form-item__content{
  margin-left: 126px !important;
}
.d12 .el-input__inner{
  padding: 0 8px !important;

}
.d12 .date_pick .el-input__inner{
  padding-left: 36px !important;
}
.d12 .el-card__body {
  padding-bottom: 10px !important;
}

.d3 .text_area .el-form-item__content{
  margin-left: 0 !important;
}
/*.d3 .el-textarea__inner{
  height: 76px !important;
}*/

.d4 .el-form-item {
  margin-bottom: 10px !important;
}
/*.d4 .el-textarea__inner{
  height: 96px !important;
}*/
.d4 .el-form-item__content{
  margin-left: 0 !important;
}

.el-card {
  margin-bottom: 10px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.input-new-keyword {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #20a0ff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}
.avatar {
  width: 145px;
  height: 145px;
  display: block;
}
.d1 .el-card__body {
  padding: 0 20px 20px 20px !important;
}
.d12 .el-input__inner {
  width: 107px !important;
  padding: 0 2px !important;
}
.d12 .el-col-1 {
  width: 7.166667% !important;
}
.d12 .el-form-item__label {
  padding: 0 4px 0 0 !important;
}

.col_title{
  margin: 7px 0 0 30px
}
.item_yellow{
  background-color: #ffff7b;
}
.item_green{
  color: #1ab394;
  font-size: 15px;
}
.d22 .el-input {
  width: 100%;
}
.d22 .el-textarea__inner{
  width: 100% ;
}
.d22 .el-form-item__label {
  width: 126px !important;
}
.d22 .el-form-item__content{
  margin-left: 126px !important;
}
.d22 .el-input__inner{
  padding: 0 8px !important;
}
.d22 .date_pick .el-input__inner{
  padding-left: 36px !important;
}
.d22 .el-card__body {
  padding-bottom: 10px !important;
}
.js-module .el-input__inner{
  width: 160px !important;
  padding-left: 15px !important;
}
.js-module .el-select--medium{
  margin-left: 72px !important;
}
.op-container .el-input--medium .el-input__inner {
  height: 30px !important;
  line-height: 30px !important;
}
.op-container .el-input__inner{
  border: none !important;
  color: #13C2C2;
  background: #fff4e7;
}
</style>

<script>

import { updatePatient, getPatient, addPatient } from '@/api/his/patient'
import {updateAttribute, getAttribute, addAttribute} from '@/api/his/attribute'
import { addScreening, listScreening, updateScreening, delScreening, delScreeningByPid} from '@/api/his/screening'
import { getToken } from "@/utils/auth";
import { getDicts } from '@/api/system/dict/data'
import axios from 'axios'

export default  {
  name: 'PatientEdit',
  dicts: [
    'his_doctor_sex',
    'his_screening_item',
    'his_saas_type',
    'his_risk_type',
    'his_screening_calculate',
    'his_marital_type',
    'his_degree',
    'his_income',
    'his_living',
    'his_caregiver',
    'his_director',
    'his_screen',
    'his_risk_calculation_model',
    'his_screening_status',
    'sample_type',
  ],
  data() {
    return {
      activeNames: ['1','2','3'],
      dicts_state:1,
      visbleJsz: false,
      visbleKspg: false,
      tctCheck:{
        type:'',//报告类型
        formula:'',//公式
        info:{
          unit:'',
          name:'',
          gender:'',
          age:'',
          sno:'',//样本编号
          hno:'',//门诊号
          type:'',//样本类型
          dept:'',//送检科室
          docts:'',//送检医生
        },
        check:{
          mda:'',
          bmi:'',
          rsp:'',//卧位收缩压
          kdp:'',//卧位舒张压
        },
        risk:{
          jresult:'',//肌少症结果
          jrange:'',//参考范围
          jrisk:'',//肌少症风险
          sresult:'',//衰弱结果
          srange:'',//参考范围
          srisk:'',//风险
          advise:''//建议
        },
        read:{
          rectime:'',//送检时间
          reptime:'',//报告时间
          revtime:'',//审核时间
          inspector:'',//检验人
          report:'',//报告人
          reviewer:'',//审核人
          lc:'',//临床
        }
      },
      // 表单参数
      formPatient: {},
      formAttribute:{
        patientId:0,
        alb:'',
        ast:'',
        rsp:'',
        kdp:'',
        vd:'',
        cre:'',
        fa:'',
        rbc:'',
        fpg:'',
        hgb:'',
        mcv:'',
        acp:'',
        p:'',
        k:'',
        tp:'',
        na:'',
        il:'',
        trh:'',
        ft4:'',
        cc:'',
        mda:'',
        b12:'',
        wbc:'',
        plt:'',
        tag:'',
        alt:'',
        ldl:'',
        hba1c:'',
        hcy:'',
        hvd:'',
        bmi:'',
        formula:'',
        id:''
      },
      formResult:{},
      formQuery:{},
      formAdvise:{},
      formRisk:{},
      riskModle:'二元 Logistics 回归',
      imageBase64:[],
      reportList:[
        {label:'PDF',value:'1'},
        {label:'IMG',value:'2'},
      ],
      reportType:'1',
      resImage:'',
      // 表单校验
      rulesPatient: {
        patientName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        idCard: [
          { required: false, message: "身份证号不能为空", trigger: "blur" }
        ],
        gender: [
          { required: false, message: "性别不能为空", trigger: "change" }
        ],
        unit: [
          { required: false, message: "采血单位不能为空", trigger: "blur" }
        ],
        slice_no: [
          { required: true, message: "血片编号不能为空", trigger: "blur" }
        ],
        ctime: [
          { required: true, message: "采血日期不能为空", trigger: "blur" }
        ],
        weight: [
          { required: false, message: "体重不能为空", trigger: "blur" }
        ],
        marital: [
          { required: false, message: "婚姻状况不能为空", trigger: "blur" }
        ],
        degree: [
          { required: false, message: "文化程度不能为空", trigger: "blur" }
        ],
        tel: [
          { required: false, message: "电话手机号不能为空", trigger: "blur" }
        ],
        collector: [
          { required: false, message: "采血人不能为空", trigger: "blur" }
        ],
        inputby: [
          { required: false, message: "信息录入者不能为空", trigger: "blur" }
        ],
        reviewer: [
          { required: false, message: "审核者不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: false, message: "录入时间不能为空", trigger: "blur" }
        ],
      },
      rulesAttribute:{},
      rulesResult:{
        screeningItem:[
          {required: true, message: "请选择筛查项目", trigger: "blur" }
        ],
        screeningResult:[
          {required: true, message: "筛查结果不能为空", trigger: "blur" }
        ],
        referenceRange:[
          {required: true, message: "参考范围不能为空", trigger: "blur" }
        ],
        riskWarning:[
          {required: true, message: "请选择风险类型", trigger: "blur" }
        ]
      },
      rulesAdvise:{},
      rulesRisk:{
        collector: [
          { required: false, message: "采血人不能为空", trigger: "blur" }
        ],
        inputby: [
          { required: false, message: "信息录入者不能为空", trigger: "blur" }
        ],
        reviewer: [
          { required: false, message: "审核人不能为空", trigger: "blur" }
        ],
        inspector: [
          { required: false, message: "检验人不能为空", trigger: "blur" }
        ],
      },
      btnLoading: false,
      isExit: false,
      resultVisiable: false,
      screeningLn: [],
      screeningKs: [],
      queryLnParams: {
        patientId: 0,
        subscreening:'实验室老年衰弱/肌少症筛查'
      },
      queryKsParams: {
        patientId: 0,
        subscreening:'快速综合评估'
      },
      selectOptions:{
        status:[],
        riskType:[]
      },
      // 导入指标参数
      upload: {
        patientId: 0,
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        //url: process.env.VUE_APP_BASE_API + "/his/attribute/importData"
        url: process.env.VUE_APP_BASE_API + "/his/attribute/batchImportData"
      },
      pathUrl:'/plugins/pdfjs/web/viewer.html',
      doc:{
        open: false,
        title: '预览'
      }
    }
  },
  mounted () {

  },
  created() {
    this.init();
    //this.getDicts();
  },

  methods: {
    getBmi(){
      let weight = this.formPatient.weight;
      let height = this.formPatient.height / 100; // 将厘米转换为米
      if(weight!=null && height!=null && weight!='' && height!=''){
        let bmi = weight/(height**2)
        this.formAttribute.bmi = bmi.toFixed(2);// 保留两位小数
      }else {
        this.formAttribute.bmi = ''; // 清空无效输入
      }
    },
    handleChange(val) {
      //console.log(val);
    },
    async loadPdf() {
      if(this.screeningLn.length==0){
        this.$modal.msgWarning("请先上传检测指标进行计算");
        return false;
      }

      //console.log('this.tctCheck: ',JSON.stringify(this.tctCheck));return;
      const loading = this.$loading({
        //lock: true,
        text: '报告生成中，请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.2)'
      });

      this.tctCheck.type = this.reportType

      const baseURL = process.env.VUE_APP_BASE_API;
      const api ='/his/patient/jszReport';
      var query = this.tctCheck;
      var url = baseURL + api ;
      axios.post(url, query, {
        headers: {
          Authorization: "Bearer " + getToken()
        },
        responseType: 'blob',
      }).then(res =>{
          loading.close();
          let blob = null;
          if(this.reportType=='1'){
            blob = new Blob([res.data], {type: 'application/pdf'})
          }
          else if(this.reportType=='2'){
            blob = new Blob([res.data], {type: 'image/jpeg'})
          }else{
            //默认pdf格式
            blob = new Blob([res.data], {type: 'application/pdf'})
          }

          let href = URL.createObjectURL(blob)
          window.open(href)
        }
      )
    },
    getFormula(rows){
      if(rows==4){
        this.fdisabled = true;
        this.$modal.alert('风险计算模型四暂不支持计算')
      }else{
        this.fdisabled = false;
      }
    },
    getDicts(){
      getDicts("his_screening_status").then(response => {
        response.data.forEach((self,index) => {
          var disabled = true;
          if(this.formPatient.status==0 && self.dictLabel === '血片不合格'){
            disabled = false;
          }
          if(this.formPatient.status==0 && self.dictLabel === '未录结果'){
            disabled = false;
          }
          this.selectOptions.status.push({ value: self.dictValue, label: self.dictLabel,disabled: disabled })
        });
      });
      getDicts("his_screening_calculate").then(response => {
        response.data.forEach((self,index) => {
          var disabled = false;
          if(self.dictLabel === '计算模型四'){
            disabled = true;
          }
          this.selectOptions.riskType.push({ value: self.dictValue, label: self.dictLabel,disabled: disabled })
        });
      });
    },

    init() {
      //const patient_id = this.$route.query.id
      const id = this.queryLnParams.patientId = this.queryKsParams.patientId = this.upload.patientId = this.$route.params && this.$route.params.id;

      getPatient(id).then(response => {
        this.formPatient = this.formRisk = this.formAdvise = response.data;

        this.tctCheck.info.name = this.formPatient.patientName;
        this.tctCheck.info.age = this.formPatient.age;
        this.tctCheck.info.gender = this.formPatient.gender;
        this.tctCheck.info.sno = this.formPatient.sliceNo;
        this.tctCheck.info.hno = this.formPatient.outpatient;
        this.tctCheck.info.type = this.formPatient.sampleType;
        this.tctCheck.info.dept = this.formPatient.department;
        this.tctCheck.info.docts = this.formPatient.docts;
        this.tctCheck.info.unit = this.formPatient.unit;

        this.tctCheck.risk.advise = this.formAdvise.lnAdvise

        this.tctCheck.read.rectime= this.formPatient.receiveTime==''||this.formPatient.receiveTime==null?'':this.formPatient.receiveTime.substring(0,10),//送检时间
          this.tctCheck.read.reptime= this.formPatient.reportTime==''||this.formPatient.reportTime==null?'':this.formPatient.reportTime.substring(0,10),//报告时间
          this.tctCheck.read.revtime= this.formPatient.reviewTime==''||this.formPatient.reviewTime==null?'':this.formPatient.reviewTime.substring(0,10),//审核时间
          this.tctCheck.read.inspector= this.formRisk.inspector,//检验人
          this.tctCheck.read.report= this.formRisk.report,//报告人
          this.tctCheck.read.reviewer= this.formRisk.reviewer,//审核人

          this.tctCheck.read.lc = this.formPatient.lc,//临床

          //获取筛查参数指标
          getAttribute(id).then(response => {
            if(response.data != undefined){
              this.formAttribute = response.data;
              this.formAttribute.formula = this.formAttribute.formula=='null'||this.formAttribute.formula==''?"":this.formAttribute.formula+"";//和字典类型匹配
              this.isExit = true;

              this.tctCheck.formula = this.formAttribute.formula;//公式
              this.tctCheck.check = this.formAttribute;
            }else{
              this.formAttribute.patientId = id;
            }
          });

        //获取筛查结果
        listScreening(this.queryLnParams).then(response => {
          this.screeningLn = response.rows;
          //console.log('this.screeningLn: ',this.screeningLn)
          this.screeningLn.forEach((item)=>{
            if(item.screeningItem=='老年衰弱/肌少症'){
              this.tctCheck.risk.jresult = item.screeningResult
              this.tctCheck.risk.jrange = item.referenceRange
              this.tctCheck.risk.jrisk = item.riskWarning
            }
            if(item.screeningItem=='老年衰弱/老年衰弱'){
              this.tctCheck.risk.sresult = item.screeningResult
              this.tctCheck.risk.srange = item.referenceRange
              this.tctCheck.risk.srisk = item.riskWarning
            }
          })
          //console.log('this.tctCheck: ',this.tctCheck)
        });
        listScreening(this.queryKsParams).then(response => {
          this.screeningKs = response.rows;
        });

        if(response.data.subscreening == '实验室老年衰弱/肌少症'){
          this.visbleJsz = true;
        }else if(response.data.subscreening == '快速综合评估'){
          this.visbleKspg = true;
        }

        this.getDicts();
      });

    },

    //初始化筛查列表
    initLn(){
      listScreening(this.queryLnParams).then(response => {
        this.screeningLn = response.rows;
      });
    },

    /** 提交按钮 */
    submitForm() {
      //this.btnLoading = tip?true:false;
      let formPatient=new Promise((resolve,reject)=>{
        this.$refs["formPatient"].validate((valid)=>{
          if(valid){
            resolve();
          }else{
            this.btnLoading = false;
            return false;
          }

        });
      });
      let formAttribute=new Promise((resolve,reject)=>{
        this.$refs["formAttribute"].validate((valid)=>{
          if(valid){
            resolve();
          }else{
            this.btnLoading = false;
            return false;
          }
        });
      });
      let formRisk=new Promise((resolve,reject)=>{
        this.$refs["formRisk"].validate((valid)=>{
          if(valid){
            resolve();
          }else{
            this.btnLoading = false;
            return false;
          }
        });
      });


      Promise.all([formPatient,formAttribute,formRisk]).then(()=>{
        //没有进行计算结果的时候可以更新指标， 计算结果之后 点更新就无法修改指标
        //更新患者疾病指标
        //console.log('this.formAttribute',JSON.stringify(this.formAttribute))
        if (this.isExit) {
          updateAttribute(this.formAttribute)
        } else {
          addAttribute(this.formAttribute)
        }

        if (this.formPatient.id != null) {
          this.formPatient.remark = this.formAdvise.remark;
          this.formPatient.riskModel = this.formRisk.riskModel;
          this.formPatient.collector = this.formRisk.collector;
          this.formPatient.reviewer = this.formRisk.reviewer;
          this.formPatient.createBy = this.formRisk.createBy;
          this.formPatient.ctime = this.formRisk.ctime;
          updatePatient(this.formPatient).then(response =>{});
        }else{
          addPatient(this.formPatient).then(response => {});
        }

        this.$modal.msgSuccess("更新成功");
        this.$router.push({ path: '/jsz/patient'})

      })

    },

    /*计算按钮操作*/
    submitCalculation() {
      if(this.formAttribute.formula=='1'){
        this.formula1();
      }
      if(this.formAttribute.formula=='2'){
        this.formula2();
      }
      if(this.formAttribute.formula=='3'){
        this.formula3();
      }
      if(this.formAttribute.formula=='4'){
        this.formula4();
      }
      if(this.formAttribute.formula=='5'){
        this.formula5();
      }
    },

    //公式一
    formula1(){
      this.$message.warning('计算模型一请在“衰弱/肌少症”列表中进行计算');
    },
    //公式二
    formula2(){
      this.$message.warning('计算模型二请在“衰弱/肌少症”列表中进行计算');
    },
    //公式三
    formula3() {
      const age = this.formPatient.age;
      const mda = this.formAttribute.mda;
      const bmi = this.formAttribute.bmi;
      const rsp = this.formAttribute.rsp;// 收缩压
      const kdp = this.formAttribute.kdp;// 舒张压

      // 输入验证（必须为有效正数）
      if ([age, mda, bmi, rsp, kdp].some(v =>
        isNaN(v) ||
        v <= 0 ||
        !isFinite(v)
      )) {
        this.$message.error('请输入有效的正数值');
        this.formResult.screeningResult = '';
        return;
      }
      try {
        // ==== 核心公式计算 ====
        // 计算线性组合
        const intercept = 45.5362628173523;
        const z = intercept +
          0.335165212205523 * mda +
          0.375107513059018 * age +
          0.294977836065515 * bmi +
          (-0.365904257401974) * rsp +
          (-0.45996009924074) * kdp;
        // 安全计算指数（处理数值溢出）
        let expZ;
        if (z > 709) { // 超过JS能表示的最大exp值
          expZ = Infinity;
        } else if (z < -745) { // 超过最小可表示值
          expZ = 0;
        } else {
          expZ = Math.exp(z);
        }
        // 计算最终概率
        const P = expZ / (1 + expZ || 1); // 防止除以零
        //const accResult = P.toFixed(2);//保留两位小数
        //用科学计数法表示
        const accResult = P.toExponential(2);
        //console.log('accResult ',accResult);return;
        //如果已计算先删除计算结果
        delScreeningByPid({patientId:this.formPatient.id}).then(response=>{
            if(response.code==200){
              this.formResult.subscreening = '实验室老年衰弱/肌少症筛查';
              this.formResult.screeningItem = '老年衰弱/老年衰弱';
              this.formResult.patientId = this.formPatient.id;
              this.formResult.addTime = Date.now();
              this.formResult.screeningResult = accResult;
              this.formResult.screeningType = '0';
              //诊断结果
              this.formResult.referenceRange = "0～1";
              if(accResult>=0 && accResult<0.33){
                this.formResult.riskWarning ="低风险";
                this.formResult.advise ="无衰弱症状";
              }else if(accResult>0.33 && accResult<0.67){
                this.formResult.riskWarning ="中风险";
                this.formResult.advise ="科学膳食、经常锻炼";
              }else if(accResult>0.67 && accResult<=1){
                this.formResult.riskWarning ="高风险";
                this.formResult.advise ="请及时就医检查";
              }else{
                this.formResult.riskWarning ="~非临床数据~";
              }

              addScreening(this.formResult).then(response => {
                if(response.code==200){
                  //更新指标
                  updateAttribute(this.formAttribute).then(res=>{
                    if(res.code==200){
                      //更新计算状态status=2已计算
                      this.formPatient.status ='2';
                      updatePatient(this.formPatient).then(res =>{
                        if(res.code==200){
                          this.$modal.msgSuccess("计算成功");
                          this.init()
                        }
                      });
                    }
                  })
                }
              });
            }
        })
      } catch (error) {
        console.error('计算错误:', error);
        this.$message.error('计算过程中发生错误');
        this.prerecord.screeningResult = '';
      }
    },
    //公式四
   async formula4(){
      //--------衰弱公式-------//
     const age = this.formPatient.age;
     const mda = this.formAttribute.mda;
     const bmi = this.formAttribute.bmi;
     const rsp = this.formAttribute.rsp;// 收缩压
     const kdp = this.formAttribute.kdp;// 舒张压

     // 输入验证（必须为有效正数）
     if ([age, mda, bmi, rsp, kdp].some(v =>
       isNaN(v) ||
       v <= 0 ||
       !isFinite(v)
     )) {
       this.$message.error('请输入有效的正数值');
       this.formResult.screeningResult = '';
       return;
     }
       // ==== 核心公式计算 ====
       // 计算线性组合
       const intercept1 = 45.5362628173523;
       const z1 = intercept1 +
         0.335165212205523 * mda +
         0.375107513059018 * age +
         0.294977836065515 * bmi +
         (-0.365904257401974) * rsp +
         (-0.45996009924074) * kdp;
       // 安全计算指数（处理数值溢出）
       let expZ1;
       if (z1 > 709) { // 超过JS能表示的最大exp值
         expZ1 = Infinity;
       } else if (z1 < -745) { // 超过最小可表示值
         expZ1 = 0;
       } else {
         expZ1 = Math.exp(z1);
       }
       // 计算最终概率
       const P1 = expZ1 / (1 + expZ1 || 1); // 防止除以零
       //const accResultSr = P1.toFixed(2);//保留两位小数
     //用科学计数法表示
       const accResultSr = P1.toExponential(2);
       //--------肌少症公式-------//
       const xtw = this.formAttribute.xtw;     // 小腿围(cm)
       const wl = this.formAttribute.wl;       // 握力(kg)
       const sbs = this.formAttribute.sbs;     // 6米步速(m/s)

       // 输入验证（必须为有效正数）
       if ([mda, xtw, wl, bmi, sbs].some(v =>
         isNaN(v) ||
         v <= 0 ||
         !isFinite(v)
       )) {
         this.$message.error('请输入有效的正数值');
         this.formResult.screeningResult = '';
         return;
       }

         // ==== 核心公式计算 ====
         const intercept2 = 121.590762014252;
         const z2 = intercept2 +
           (-0.00693586793154646) * mda +
           (-1.87991214244854) * xtw +
           (-0.553399249527378) * wl +
           (-1.93007115165514) * bmi +
           0.0335951701097914 * sbs;

         // 安全计算指数
         let expZ2;
         if (z2 > 709) {         // 防止数值上溢
           expZ2 = Infinity;
         } else if (z2 < -745) { // 防止数值下溢
           expZ2 = 0;
         } else {
           expZ2 = Math.exp(z2);
         }

         // 计算最终概率（带安全除法）
        const P2 = expZ2 / (1 + expZ2 || 1);// 防止除以零
        //const accResultJs = P2.toFixed(2);//保留两位小数
     //用科学计数法表示
     const accResultJs = P2.toExponential(2);
        //console.log('accResult ',accResult+' - '+accResultSr);return;

       //如果已计算先删除计算结果
       delScreeningByPid({patientId:this.formPatient.id}).then(response=>{
         if(response.code==200){
           //肌少症
           this.formResult.patientId = this.formPatient.id;
           this.formResult.subscreening = '实验室老年衰弱/肌少症筛查';
           this.formResult.screeningItem = '老年衰弱/肌少症';

           //诊断结果
           this.formResult.referenceRange = "0～1";
           if(accResultJs>=0 && accResultJs<0.33){
             this.formResult.riskWarning ="低风险";
             this.formResult.advise ="无衰弱症状";
           }else if(accResultJs>0.33 && accResultJs<0.67){
             this.formResult.riskWarning ="中风险";
             this.formResult.advise ="科学膳食、经常锻炼";
           }else if(accResultJs>0.67 && accResultJs<=1){
             this.formResult.riskWarning ="高风险";
             this.formResult.advise ="请及时就医检查";
           }else{
             this.formResult.riskWarning ="~非临床数据~";
           }
           this.formResult.addTime = Date.now();
           this.formResult.screeningResult = accResultJs;
           this.formResult.screeningType = '0';
           addScreening(this.formResult).then(response => {
             if(response.code==200){
               //增加衰弱
               this.formResult.subscreening = '实验室老年衰弱/肌少症筛查';
               this.formResult.screeningItem = '老年衰弱/老年衰弱';
               //this.formResult.patientId = this.formPatient.id;

               //诊断结果
               this.formResult.referenceRange = "0～1";
               if(accResultSr>=0 && accResultSr<0.33){
                 this.formResult.riskWarning ="低风险";
                 this.formResult.advise ="无衰弱症状";
               }else if(accResultSr>0.33 && accResultSr<0.67){
                 this.formResult.riskWarning ="中风险";
                 this.formResult.advise ="科学膳食、经常锻炼";
               }else if(accResultSr>0.67 && accResultSr<=1){
                 this.formResult.riskWarning ="高风险";
                 this.formResult.advise ="请及时就医检查";
               }else{
                 this.formResult.riskWarning ="~非临床数据~";
               }
               this.formResult.addTime = Date.now();
               this.formResult.screeningResult = accResultSr;
               this.formResult.screeningType = '0';
               addScreening(this.formResult).then(response => {
                 if(response.code==200){
                   //更新指标
                   updateAttribute(this.formAttribute).then(res=>{
                     if(res.code==200){
                       //更新计算状态status=2已计算
                       this.formPatient.status ='2';
                       updatePatient(this.formPatient).then(res =>{
                         if(res.code==200){
                           this.$modal.msgSuccess("计算成功");
                           this.init()
                         }
                       });
                     }
                   })
                 }
               });
             }
           });
         }
       })
    },
    //公式五
    async formula5(){
      //--------衰弱公式-------//
      const age = this.formPatient.age;
      const mda = this.formAttribute.mda;
      const bmi = this.formAttribute.bmi;
      const rsp = this.formAttribute.rsp;// 收缩压
      const kdp = this.formAttribute.kdp;// 舒张压

      // 输入验证（必须为有效正数）
      if ([age, mda, bmi, rsp, kdp].some(v =>
        isNaN(v) ||
        v <= 0 ||
        !isFinite(v)
      )) {
        this.$message.error('请输入有效的正数值');
        this.formResult.screeningResult = '';
        return;
      }
      // ==== 核心公式计算 ====
      // 计算线性组合
      const intercept1 = 45.5362628173523;
      const z1 = intercept1 +
        0.335165212205523 * mda +
        0.375107513059018 * age +
        0.294977836065515 * bmi +
        (-0.365904257401974) * rsp +
        (-0.45996009924074) * kdp;
      // 安全计算指数（处理数值溢出）
      let expZ1;
      if (z1 > 709) { // 超过JS能表示的最大exp值
        expZ1 = Infinity;
      } else if (z1 < -745) { // 超过最小可表示值
        expZ1 = 0;
      } else {
        expZ1 = Math.exp(z1);
      }
      // 计算最终概率
      const P1 = expZ1 / (1 + expZ1 || 1); // 防止除以零
     // const accResultSr = P1.toFixed(2);//保留两位小数
      //用科学计数法表示
      const accResultSr = P1.toExponential(2);

      //--------肌少症公式-------//
      const xtw = this.formAttribute.xtw;     // 小腿围(cm)
      const wl = this.formAttribute.wl;       // 握力(kg)

      // 输入验证（必须为有效正数）
      if ([mda, xtw, wl].some(v =>
        isNaN(v) ||
        v <= 0 ||
        !isFinite(v)
      )) {
        this.$message.error('请输入有效的正数值');
        this.formResult.screeningResult = '';
        return;
      }

      // ==== 核心公式计算 ====
      const intercept2 = 51.0112355474466;
      const z2 = intercept2 +
        (-0.00262658329088984) * mda +
        (-1.27714971978413) * xtw +
        (-0.366337016299275) * wl;

      // 安全计算指数
      let expZ2;
      if (z2 > 709) {         // 防止数值上溢
        expZ2 = Infinity;
      } else if (z2 < -745) { // 防止数值下溢
        expZ2 = 0;
      } else {
        expZ2 = Math.exp(z2);
      }

      // 计算最终概率（带安全除法）
      const P2 = expZ2 / (1 + expZ2 || 1);// 防止除以零
      //const accResultJs = P2.toFixed(2);//保留两位小数
      //用科学计数法表示
      const accResultJs = P2.toExponential(2);
      //console.log('accResultJs ',accResultJs+' - '+accResultSr);return;

      //如果已计算先删除计算结果
      delScreeningByPid({patientId:this.formPatient.id}).then(response=>{
        if(response.code==200){
          //肌少症
          this.formResult.patientId = this.formPatient.id;
          this.formResult.subscreening = '实验室老年衰弱/肌少症筛查';
          this.formResult.screeningItem = '老年衰弱/肌少症';

          //诊断结果
          this.formResult.referenceRange = "0～1";
          if(accResultJs>=0 && accResultJs<0.33){
            this.formResult.riskWarning ="低风险";
            this.formResult.advise ="无衰弱症状";
          }else if(accResultJs>0.33 && accResultJs<0.67){
            this.formResult.riskWarning ="中风险";
            this.formResult.advise ="科学膳食、经常锻炼";
          }else if(accResultJs>0.67 && accResultJs<=1){
            this.formResult.riskWarning ="高风险";
            this.formResult.advise ="请及时就医检查";
          }else{
            this.formResult.riskWarning ="~非临床数据~";
          }
          this.formResult.addTime = Date.now();
          this.formResult.screeningResult = accResultJs;
          this.formResult.screeningType = '0';
          addScreening(this.formResult).then(response => {
            if(response.code==200){
              //增加衰弱
              this.formResult.subscreening = '实验室老年衰弱/肌少症筛查';
              this.formResult.screeningItem = '老年衰弱/老年衰弱';
              //this.formResult.patientId = this.formPatient.id;

              //诊断结果
              this.formResult.referenceRange = "0～1";
              if(accResultSr>=0 && accResultSr<0.33){
                this.formResult.riskWarning ="低风险";
                this.formResult.advise ="无衰弱症状";
              }else if(accResultSr>0.33 && accResultSr<0.67){
                this.formResult.riskWarning ="中风险";
                this.formResult.advise ="科学膳食、经常锻炼";
              }else if(accResultSr>0.67 && accResultSr<=1){
                this.formResult.riskWarning ="高风险";
                this.formResult.advise ="请及时就医检查";
              }else{
                this.formResult.riskWarning ="~非临床数据~";
              }
              this.formResult.addTime = Date.now();
              this.formResult.screeningResult = accResultSr;
              this.formResult.screeningType = '0';
              addScreening(this.formResult).then(response => {
                if(response.code==200){
                  //更新指标
                  updateAttribute(this.formAttribute).then(res=>{
                    if(res.code==200){
                      //更新计算状态status=2已计算
                      this.formPatient.status ='2';
                      updatePatient(this.formPatient).then(res =>{
                        if(res.code==200){
                          this.$modal.msgSuccess("计算成功");
                          this.init()
                        }
                      });
                    }
                  })
                }
              });
            }
          });
        }
      })
    },
    //公式六
    formula6(){
      const mda = this.formAttribute.mda;      // MDA
      const xtw = this.formAttribute.xtw;     // 小腿围(cm)
      const wl = this.formAttribute.wl;       // 握力(kg)
      const bmi = this.formAttribute.bmi;     // BMI
      const sbs = this.formAttribute.sbs;     // 6米步速(m/s)

      // 输入验证（必须为有效正数）
      if ([mda, xtw, wl, bmi, sbs].some(v =>
        isNaN(v) ||
        v <= 0 ||
        !isFinite(v)
      )) {
        this.$message.error('请输入有效的正数值');
        this.formResult.screeningResult = '';
        return;
      }

      try {
        // ==== 核心公式计算 ====
        const intercept = 121.590762014252;
        const z = intercept +
          (-0.00693586793154646) * mda +
          (-1.87991214244854) * xtw +
          (-0.553399249527378) * wl +
          (-1.93007115165514) * bmi +
          0.0335951701097914 * sbs;

        // 安全计算指数
        let expZ;
        if (z > 709) {         // 防止数值上溢
          expZ = Infinity;
        } else if (z < -745) { // 防止数值下溢
          expZ = 0;
        } else {
          expZ = Math.exp(z);
        }

        // 计算最终概率（带安全除法）
        const P = expZ === Infinity ? 1 : expZ / (1 + expZ);// 防止除以零
        const accResultSr = (P * 100).toFixed(2);//保留两位小数

        // ==== 结果处理 ====
        //this.formResult.screeningResult = result;
        //this.showResultDialog = true;  // 显示结果弹窗
        //console.log('Result ',Result);return;
        // ==== 查询条件 ====
        //肌少症
        this.formResult.subscreening = '实验室老年衰弱/肌少症筛查';
        this.formResult.screeningItem = '老年衰弱/肌少症';
        this.formResult.patientId = this.formPatient.id;
        this.controlTip = false;//关闭更新提示
        listScreening(this.formResult).then(response => {
          if(response.code==200) {
            //诊断结果
            this.formResult.referenceRange = "0～1";
            if(accResultSr>=0 && accResultSr<0.33){
              this.formResult.riskWarning ="低风险";
              this.formResult.advise ="无肌少症症状";
            }else if(accResultSr>0.33 && accResultSr<0.67){
              this.formResult.riskWarning ="中风险";
              this.formResult.advise ="科学膳食、经常锻炼";
            }else if(accResultSr>0.67 && accResultSr<=1){
              this.formResult.riskWarning ="高风险";
              this.formResult.advise ="请及时就医检查";
            }else{
              this.formResult.riskWarning ="~非临床数据~";
            }
            //更新或添加筛查记录
            if (response.rows.length == 1) {
              this.formResult.sid = response.rows[0].sid;
              this.formResult.updateTime = Date.now();
              this.formResult.screeningResult = accResult;
              this.formResult.screeningType = '0';
              updateScreening(this.formResult).then(response => {
                this.$modal.msgSuccess("计算更新成功");
                this.submitForm(false)
                this.initLn()
              })
            } else if (response.rows.length == 0) {
              this.formResult.addTime = Date.now();
              this.formResult.screeningResult = accResult;
              this.formResult.screeningType = '0';
              addScreening(this.formResult).then(response => {
                this.$modal.msgSuccess("计算成功");
                this.submitForm(false)
                this.initLn()
              });
            }
          }
        });


      } catch (error) {
        console.error('计算错误:', error);
        this.$message.error('计算过程中发生错误');
        this.formResult.screeningResult = '';
      }
    },

    handlePatientResult(row,type) {
      this.dicts_state = type
      this.formResult = Object.assign({}, row)
      this.resultVisiable = true
    },

    handleDelete(row){
      let id = row.sid ;
      let ids = [id];
      this.$modal.confirm('是否确认删除"' + row.screeningItem + '"的数据项？').then(function() {
        return delScreening(ids);
      }).then(() => {
        this.init();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});

    },

    handleResultEdit() {
      this.$refs["formResult"].validate(valid => {
        if (valid) {
          this.formResult.addTime = Date.now();
          if (this.formResult.sid != null) {
            updateScreening(this.formResult).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.resultVisiable = false;
              //this.init();
              listScreening(this.queryLnParams).then(response => {
                this.screeningLn = response.rows;
              });
            });
          } else {
            this.formResult.patientId = this.queryKsParams.patientId = this.queryLnParams.patientId;
            addScreening(this.formResult).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.resultVisiable = false;
              this.init();
            });
          }
        }
      });
    },

    handleCancel: function() {
      this.$router.push({ path: '/jsz/patient'})
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "筛查结果导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('his/attribute/importTemplate', {
      }, `attribute_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.init();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },

    back(){
      this.$router.push({path:'/jsz/patient'})
    }

  }
}
</script>
